package Eyjafjalla.card.attack;

import Eyjafjalla.action.EyjafjallaAttackAction;
import Eyjafjalla.action.PushAction;
import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.panel.CloudEnergyPanel;
import Eyjafjalla.patch.CloudPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.ui.panels.EnergyPanel;

public class Darkside_Eyjafjalla extends AbstractEyjafjallaCard {
    public static final String ID = "Darkside_Eyjafjalla";
    private static final CardStrings cardStrings;

    public Darkside_Eyjafjalla(){
        super(ID, cardStrings.NAME,0,cardStrings.DESCRIPTION,CardType.ATTACK,CardRarity.UNCOMMON,CardTarget.ENEMY);
        this.baseDamage = 4;
        this.damage = 4;
        setFireDescription(cardStrings.EXTENDED_DESCRIPTION[0]);
    }

    @Override
    public AbstractCard makeCopy() {
        return new Darkside_Eyjafjalla();
    }

    @Override
    public void calculateCardDamage(AbstractMonster mo) {
        int trueD = baseDamage;
        int level = 0;
        if(isFire()){
            level = 1;
        }
        baseDamage = calAttack(baseDamage,level);
        super.calculateCardDamage(mo);
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
    }

    @Override
    public void applyPowers() {
        int trueD = baseDamage;
        int level = 0;
        if(isFire()){
            level = 1;
        }
        baseDamage = calAttack(baseDamage,level);
        super.applyPowers();
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
    }

    private int calAttack(int baseDamage,int level){
        if(CloudEnergyPanel.getCurrentEnergy()<=level)
            baseDamage*=2;
        if(EnergyPanel.getCurrentEnergy()<=level)
            baseDamage*=2;
        if(CloudPatch.cloudGroup.size()<=(CloudPatch.cloudGroup.contains(this)?level+1:level))
            baseDamage*=2;
        if(AbstractDungeon.player.hand.size()<=(AbstractDungeon.player.hand.contains(this)?level+1:level))
            baseDamage*=2;
        return baseDamage;
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new EyjafjallaAttackAction());
        addToBot(new DamageAction(m,new DamageInfo(p,damage,damageTypeForTurn), AbstractGameAction.AttackEffect.SLASH_VERTICAL));
    }

    @Override
    public void upgrade() {
        if(!this.upgraded){
            upgradeName();
            upgradeDamage(2);
        }
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}


